package com.example.myapplication;

import androidx.annotation.NonNull;

import android.app.ListActivity;
import android.os.Bundle;
import android.os.Handler;
import android.os.Looper;
import android.os.Message;
import android.widget.SimpleAdapter;
import android.widget.Toast;

import java.util.ArrayList;
import java.util.HashMap;

public class RateListActivity3 extends ListActivity {
    private Handler handler;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        //准备数据
        ArrayList<HashMap<String,String>>listItems=new ArrayList<HashMap<String, String>>();
        for(int i=0;i<10;i++){
            HashMap<String,String>map=new HashMap<String, String>();
            map.put("ItemTitle","Rate:"+i);
            map.put("ItemDetail","detail:"+i);
            listItems.add(map);
        }

        //准备适配器

                    SimpleAdapter listItemAdapter = new SimpleAdapter(RateListActivity3.this, listItems,
                            R.layout.list_item,
                            new String[]{"ItemTitle", "ItemDetail"},
                            new int[]{R.id.itemTitle, R.id.itemDetail}
                    );



        //绑定
       handler=new Handler(Looper.myLooper()){
           @Override
           public void handleMessage(@NonNull Message msg) {
               if(msg.what==9){
                   Toast.makeText(RateListActivity3.this,"数据已更新",Toast.LENGTH_SHORT).show();
                   ArrayList<HashMap<String,String>>list2=new ArrayList<HashMap<String, String>>();
//                   SimpleAdapter listItemAdapter = new SimpleAdapter(list_item.this, listItems,
//                           R.layout.activity_list_item,
//                           new String[]{"ItemTitle", "ItemDetail"},
//                           new int[]{R.id.itemTitle, R.id.itemDetail}
//                   );
                   MyAdapter myAdapter=new MyAdapter(RateListActivity3.this,R.layout.list_item,list2);
                   setListAdapter(listItemAdapter);
               }
               super.handleMessage(msg);
           }
       };
    }
}